<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <!-- import CSS -->
<link rel="stylesheet" href="hd/index.css">
</head>
<body>
<div id="app">
    <div style="margin-top: 20px">
        <el-button size="small" type="primary" @click="add">新增</el-button>
        <el-button  size="small" type="danger" @click="remove">批量删除</el-button>
    </div>
    <el-table
            ref="multipleTable"
            :data="tableData"
            tooltip-effect="dark"
            style="width: 100%"
            @selection-change="handleSelectionChange">
        <el-table-column
                type="selection"
                width="55">
        </el-table-column>
<!--        <el-table-column-->
<!--                label="日期"-->
<!--                width="120">-->
<!--            <template slot-scope="scope">{{ scope.row.date }}</template>-->
<!--        </el-table-column>-->
        <el-table-column
                prop="id"
                label="id"
                width="120">
        </el-table-column>
        <el-table-column
                prop="name"
                label="名称"
                width="120">
        </el-table-column>
        <el-table-column
                prop="driverClass"
                label="驱动"
                width="120">
        </el-table-column>
        <el-table-column
                prop="url"
                label="地址"
                width="600">
        </el-table-column>
        <el-table-column
                prop="username"
                label="账号"
                width="120">
        </el-table-column>
        <el-table-column
                prop="password"
                label="密码"
                width="120">
        </el-table-column>
<!--        <el-table-column-->
<!--                prop="address"-->
<!--                label="地址"-->
<!--                show-overflow-tooltip>-->
<!--        </el-table-column>-->
        <el-table-column label="操作">
            <template slot-scope="scope">
                <el-button
                        size="mini"
                        @click="handleEdit(scope.row)">编辑</el-button>
                <el-button
                        size="mini"
                        type="danger"
                        @click="handleDelete(scope.row)">删除</el-button>
            </template>
        </el-table-column>
    </el-table>

    <el-dialog :title="title" :visible.sync="dialogFormVisible">
        <el-form :model="form">
            <el-form-item label="名称">
                <el-input v-model="form.name"></el-input>
            </el-form-item>
            <el-form-item label="驱动">
                <el-input v-model="form.driverClass"></el-input>
            </el-form-item>
            <el-form-item label="地址">
                <el-input v-model="form.url"></el-input>
            </el-form-item>
            <el-form-item label="账号">
                <el-input v-model="form.username"></el-input>
            </el-form-item>
            <el-form-item label="密码">
                <el-input v-model="form.password"></el-input>
            </el-form-item>

        </el-form>
        <div slot="footer" class="dialog-footer">
            <el-button @click="dialogFormVisible = false">取 消</el-button>
            <el-button type="primary" @click="submit">确 定</el-button>
        </div>
    </el-dialog>


    <div class="pagination-container">
        <el-pagination
                class="pagiantion"
                @current-change="handleCurrentChange"
                :current-page="pagination.currentPage"
                :page-size="pagination.pageSize"
                layout="total, prev, pager, next, jumper"
                :total="pagination.total">
        </el-pagination>
    </div>

</div>
</body>
<!-- import Vue before Element -->
<script src="hd/vue.js"></script>
<script src="hd/axios.js"></script>
<!-- import JavaScript -->
<script src="hd/element.js"></script>
<script>
    new Vue({
        el: '#app',
        data: function() {
            return {
                pagination: {//分页相关模型数据
                    page: 1,//当前页码
                    limit: 10,//每页显示的记录数
                    total: 100,//总记录数
                    queryString: null//查询条件
                },
                visible: false,
                tableData: [],
                multipleSelection: [],
                dialogFormVisible: false,
                form:{},
                title:"新增"



            }
        },
        created(){
            this.findPage();
        },
        methods:{
            submit(){
                axios.post("/ds/submit",this.form).then(res=>{
                    this.$message.success("操作成功");
                    this.dialogFormVisible = false
                    this.findPage()
                })
            },

            handleSelectionChange:function (val){
                this.multipleSelection = val;
            },
            //分页查询
            findPage:function(){
                axios.get("/ds/list",{
                    params:{
                        limit:this.pagination.limit,
                        page:this.pagination.page
                    }
                }).then(res=>{
                    this.tableData = res.data.page.list;
                    this.pagination.total = res.data.page.totalCount;
                })
            },
            //页码切换
            handleCurrentChange:function (val) {
                this.pagination.page = val;
                this.findPage();
            },
            add:function (){
                this.dialogFormVisible = true
                this.title = "新增"
                this.form = {}
            },

            remove:function(){
                if (this.multipleSelection.length==0){
                    this.$message.error("请选择一条数据");
                }else {
                    let ids = this.multipleSelection.map(item=>item.id);
                    this.del(ids)
                }
            },
            del:function (ids){
                axios.post("/ds/delete",ids).then(res=>{
                    this.$message.success("操作成功");
                    this.findPage()
                })
            },
            handleEdit:function (row){
                this.dialogFormVisible = true
                this.title = "修改"
                this.form = row
            },
            handleDelete:function (row){
                console.log(row)
                let arr = [];
                arr.push(row.id)
                this.del(arr)
            }
        }
    })
</script>
</html>